package org.feng.clog.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * WebMvc配置
 *
 * @author feng
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Resource
    private LoginInterceptor loginInterceptor;

    @Resource
    private LogInterceptor logInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<InterceptorRegistration> registrations = new ArrayList<>();
        registrations.add(registry.addInterceptor(loginInterceptor));
        registrations.add(registry.addInterceptor(logInterceptor));

        for (InterceptorRegistration registration : registrations) {
            registration.addPathPatterns("/**");
            registration.excludePathPatterns("/");
            registration.excludePathPatterns(
                    "/rpc/**",
                    "/api/**",
                    "/ct/**",
                    "/test/**",
                    "/favicon.ico",
                    "/swagger-resources/**",
                    "/swagger-ui.html/**",
                    "/webjars/**",
                    "/doc.html",
                    "/doc.html#/**"
            );
        }
    }
}
